package com.erp.controller.baseDataController;

import com.erp.pojo.Supplier;
import com.erp.service.baseDataService.ISupplierService;
import com.erp.utils.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * Created by jayc
 * Date:2019/1/15
 * Time:19:33
 */

@RestController
@RequestMapping("/Supplier")
public class SupplierController {

    @Autowired
    private ISupplierService supplierService;


    /**
     * 供应商操作
     */
    //查询type为供应商的所有信息
    @PostMapping("/getList")
    public Msg getList(@RequestParam(name = "page")int page,
                       @RequestParam(name = "limit")int limit){



        Msg msg1 = supplierService.getSupp("供应商",page,limit);


        return msg1;

    }

    //增加供应商
    @PostMapping("/insert")
    public void insertSup(Supplier supplier){

        supplier.setType("供应商");
        supplier.setIsystem((byte) 1);
        supplier.setEnabled(true);
        System.out.println(supplier);
        supplierService.insertSup(supplier);
    }

    //删除单条供应商
    @DeleteMapping("/delSup/{id}")
    public void delSingle(@PathVariable(value = "id")Long id){

        System.out.printf("进入删除控制器");
        supplierService.deleteSup(id);

    }

    //删除单条供应商
    @DeleteMapping("/delSups/{ids}")
    public void delMany(@PathVariable(value = "ids")String ids){

        String a[] = ids.split(",");
        System.out.println(Arrays.toString(a));

        for (int i = 0; i < a.length; i++) {
            Long id = Long.valueOf(a[i]);
            supplierService.deleteSup(id);

            System.out.printf("进入删除控制器");
        }

    }
    /**
     * 客户操作
     */
    //查询type为供应商的所有信息
    @PostMapping("/getCusList")
    public Msg getCusList(@RequestParam(name = "page")int page,
                       @RequestParam(name = "limit")int limit){

        Msg msg = supplierService.getSupp("客户",page,limit);

        return msg;

    }
    //增加客户
    @PostMapping("/insertCus")
    public void insertCus(Supplier supplier){

        supplier.setType("客户");
        supplier.setIsystem((byte) 1);
        supplier.setEnabled(true);
        System.out.println(supplier);
        supplierService.insertSup(supplier);
    }

    /**
     * 会员操作
     */
    //查询type为供应商的所有信息
    @PostMapping("/getVipList")
    public Msg getVipList(@RequestParam(name = "page")int page,
                          @RequestParam(name = "limit")int limit){

        Msg msg = supplierService.getSupp("会员",page,limit);

        return msg;

    }
    //增加会员
    @PostMapping("/insertVip")
    public void insertVip(Supplier supplier){

        supplier.setType("会员");
        supplier.setIsystem((byte) 1);
        supplier.setEnabled(true);
        System.out.println(supplier);
        supplierService.insertSup(supplier);
    }
}
